import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class SplitPackages {
    public static List<Packages> splitPackages(List<String> variables){
        List<Packages> packages = new ArrayList<Packages>();
        JavaFileExtractor javaFileExtractor = new JavaFileExtractor();

        int len = 0;
        for(String str : variables){
            if(packages.isEmpty()){  // 对分离的第一个包进行保存
                Packages pack = new Packages();
                pack.classname = new ArrayList<String>();

                pack.packageName = javaFileExtractor.extractParentDirectory(str);
                pack.classname.add(javaFileExtractor.extractFileName(str));
                pack.width = len;

                packages.add(pack);
            }
            else {
                String packName = javaFileExtractor.extractParentDirectory(str); // 获取当前要处理类的包名、类名
                String className = javaFileExtractor.extractFileName(str);

                if(packName.equals(packages.get(packages.size()-1).packageName)){
                    packages.get(packages.size()-1).width = ++len;
                    packages.get(packages.size()-1).classname.add(className);
                }
                else{
                    Packages pack = new Packages();
                    pack.classname = new ArrayList<String>();

                    pack.packageName = packName;
                    pack.classname.add(className);
                    pack.width = ++len;

                    packages.add(pack);
                }
            }
        }
        return packages;
    }
}
